package week_home_work02;

/**
 * @author zdl
 * @date 2024/11/23
 */
public class Demo47 {
    public static void main(String[] args) {
        //输出一个二维矩阵，并计算它的行列和。
        int[][] arr = {{1,2,3},{4,5,6}};
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j]+"\t");
            }
            System.out.println();
        }
        for (int i = 0; i < arr.length; i++) {
            int sum = 0;
            for (int j = 0; j < arr[i].length; j++) {
                sum+= arr[i][j];
            }
            System.out.println("第"+(i+1)+"行的和为:"+sum);
        }

        for (int i = 0; i < arr[0].length; i++) {
            int sum1= 0;
            for (int j = 0; j < arr.length; j++) {
                sum1+=arr[j][i];
            }
            System.out.println("第"+(i+1)+"列的和为"+sum1);
        }

    }
}
